﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using DAO;

namespace Sklad.WindowsApplication
{
    public partial class SendRecieveForm : Form
    {
        public static DaoRepository dr = new DaoRepository();
        static BindingList<Employer> receiveList;
        static BindingList<Employer> sendList;  

        public SendRecieveForm()
        {
            InitializeComponent();
            this.bindingSource_recieve.DataSource = new BindingList<Acceptance>(dr.AcceptanceRepository.GetAll().ToList());
            this.bindingSource_sending.DataSource = new BindingList<Extradition>(dr.ExtraditionRepository.GetAll().ToList());
            this.bindingNavigator_receive.BindingSource = this.bindingSource_recieve;
            this.bindingNavigator_sending.BindingSource = this.bindingSource_sending;
            LinkElements();

           
        }

        private void LinkElements()
        {
            #region Sending

            this.bindingNavigator_sending.BindingSource = this.bindingSource_recieve;
            this.tb_send_id.DataBindings.Add("text", this.bindingSource_sending, "Id");
            this.dp_send.DataBindings.Add("text", this.bindingSource_sending, "Date");
            this.tb_send_empl.DataBindings.Add("text", this.bindingSource_sending, "Employer");
            this.tb_provider.DataBindings.Add("text", this.bindingSource_sending, "Provider");

            #endregion

            #region Receive

            this.bindingNavigator_sending.BindingSource = this.bindingSource_recieve;
            this.tb_rec_id.DataBindings.Add("text", this.bindingSource_recieve, "Id");
            this.dp_receive.DataBindings.Add("text", this.bindingSource_recieve, "Date");
            this.tb_rec_empl.DataBindings.Add("text", this.bindingSource_recieve, "Employer");
            this.tb_client.DataBindings.Add("text", this.bindingSource_recieve, "Client");

            #endregion
            
        }

        private void UpdateData(UpdateType ut)
        {
            switch (ut)
            {
                case UpdateType.Receive:
                    this.bindingSource_recieve.DataSource = new BindingList<Acceptance>(dr.AcceptanceRepository.GetAll().ToList());
                    break;
                case UpdateType.Sending:
                    this.bindingSource_sending.DataSource = new BindingList<Extradition>(dr.ExtraditionRepository.GetAll().ToList());
                    break;
                default:
                    break;
            }
        }
    }

    enum UpdateType
    {
        Receive,
        Sending
    }
}
